﻿Public Class masdrgmaker
    Private DRGMID = Nothing
    Private MAKERNAME = Nothing
    Private MAKERADDR = Nothing
    Private MAKERTEL = Nothing
    Private MAKEREMAIL = Nothing
    Private REMARK = Nothing
    Private STATUS = Nothing
    Private selectMasdrgmaker = "SELECT `drgmid` as 'รหัสผู้ผลิตยา', `makername` as 'ชื่อผู้ผลิตยา', `makeraddr` as 'ที่อยู่', `makertel` as 'โทรศัพท์', `makeremail` as 'E-mail', `remark` as 'หมายเหตุ', `status` as 'สถานะการเปิดใช้งาน' FROM masdrgmaker"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property DRGMID_ As Integer
        Get
            Return DRGMID
        End Get
        Set(value As Integer)
            DRGMID = value
        End Set
    End Property

    Property MAKERNAME_ As String
        Get
            Return MAKERNAME
        End Get
        Set(value As String)
            MAKERNAME = value
        End Set
    End Property

    Property MAKERADDR_ As String
        Get
            Return MAKERADDR
        End Get
        Set(value As String)
            MAKERADDR = value
        End Set
    End Property

    Property MAKERTEL_ As String
        Get
            Return MAKERTEL
        End Get
        Set(value As String)
            MAKERTEL = value
        End Set
    End Property

    Property MAKEREMAIL_ As String
        Get
            Return MAKEREMAIL
        End Get
        Set(value As String)
            MAKEREMAIL = value
        End Set
    End Property

    Property REMARK_ As String
        Get
            Return REMARK
        End Get
        Set(value As String)
            REMARK = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrgmaker_ As String
        Get
            Return selectMasdrgmaker
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrgmakerData()
        If TypeOf MAKERNAME Is String Then
            If connect.GetTable("SELECT drgmid FROM masdrgmaker WHERE makername = '" & MAKERNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลผู้ผลิตยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrgmaker (makername, makeraddr, makertel, makeremail, remark, status) VALUES ('" & MAKERNAME & "', '" & MAKERADDR & "', '" & MAKERTEL & "', '" & MAKEREMAIL & "', '" & REMARK & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลผู้ผลิตยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrgmakerData()
        If TypeOf MAKERNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrgmaker SET makername = '" & MAKERNAME & "', makeraddr = '" & MAKERADDR & "', makertel = '" & MAKERTEL & "', makeremail = '" & MAKEREMAIL & "', remark = '" & REMARK & "', status = '" & STATUS & "' WHERE drgmid = '" & DRGMID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลผู้ผลิตยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
